"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var rambda_1 = require("rambda");
var ramda_1 = require("ramda");
var util_1 = require("./util");
var square = function (x) { return x * x; };
var sqrt = Math.sqrt;
//过程式
var vlen_1 = function (v) {
    var sum = 0;
    for (var i = 0; i < v.length; i++) {
        sum += square(v[i]);
    }
    return sqrt(sum);
};
util_1.log(vlen_1([1, 2, 3]));
//--------------------------
//大众函数式
var vlen_2 = function (v) {
    return sqrt(v.map(square).reduce(function (x, y) { return x + y; }));
};
console.log(vlen_2([1, 2, 3]));
//--------------------------
//经典函数式
var vlen_3 = rambda_1.compose(sqrt, ramda_1.sum, ramda_1.map(square));
console.log(vlen_3([1, 2, 3]));
//--------------------------
var nextLine = function (prevLine) {
    return [1].concat(ramda_1.aperture(2, prevLine).map(ramda_1.sum), [1]);
};
var yanghui = util_1.recursiveOf(nextLine, [1]);
console.log(util_1.take(5)(yanghui())
    .map(ramda_1.join(' '))
    .map(function (x, i) { return ' '.repeat(5 - i) + x; })
    .join('\n'));
//aperture:用来计算数列的差
console.log(ramda_1.aperture(2, [1, 2, 3, 4, 5, 8]).map(function (_a) {
    var a = _a[0], b = _a[1];
    return b - a;
}));
console.log(ramda_1.aperture(2, [1, 2, 3, 4, 5, 8]).map(vlen_3));
console.log(util_1.take(5)(util_1.recursiveOf(function (x) { return x * 2; }, 9)()));
